package com.hwua.tonyshop.controller.fg;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hwua.tonyshop.criteria.BannerCriteria;
import com.hwua.tonyshop.criteria.GoodsClassCriteria;
import com.hwua.tonyshop.criteria.GoodsInfoCriteria;
import com.hwua.tonyshop.criteria.MenuInfoCriteria;
import com.hwua.tonyshop.entity.mojo.BannerAO;
import com.hwua.tonyshop.entity.mojo.GoodsClassAO;
import com.hwua.tonyshop.entity.mojo.GoodsInfoAO;
import com.hwua.tonyshop.entity.mojo.MenuInfoAO;
import com.hwua.tonyshop.service.IBannerService;
import com.hwua.tonyshop.service.IGoodsClassService;
import com.hwua.tonyshop.service.IGoodsInfoService;
import com.hwua.tonyshop.service.IMenuInfoService;
import com.slkj.autocode.entity.ServiceResult;

@Controller
@RequestMapping(value = "/fore/index")
public class IndexController {
	@Resource
	IMenuInfoService menuInfoService;
	@Resource
	IGoodsClassService goodsClassService;
	@Resource
	IBannerService bannerService;
	@Resource
	IGoodsInfoService goodsInfoService;
	/**
	 * 跳转到前台首页
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toIndexPage", method = { RequestMethod.GET, RequestMethod.POST })
	public String toIndexPage(String token,Model model,HttpServletRequest request,HttpServletResponse response) {
	  	model.addAttribute("token",token);
		return "foreground/public/index";
	}
	
	//获取菜单
	@RequestMapping(value = "/getMenus", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ServiceResult<List<MenuInfoAO>> getMenus(Model model,HttpServletRequest request,HttpServletResponse response) {
		MenuInfoCriteria criteria = new MenuInfoCriteria();
		criteria.andStateEquals("0");
		return menuInfoService.selectByCriteria(criteria);
	}
	//获取菜单下的商品
	@RequestMapping(value = "/getMenuGoodsInfos", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ServiceResult<List<GoodsInfoAO>> getMenuGoodsInfos(Integer menuId,Model model,HttpServletRequest request,HttpServletResponse response) {
		GoodsInfoCriteria criteria = new GoodsInfoCriteria();
		criteria.andMenuIdEquals(menuId).andStateEquals("0");
		return goodsInfoService.selectByCriteria(criteria);
	}
	//获取分类
	@RequestMapping(value = "/getGoodsClasses", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ServiceResult<List<GoodsClassAO>> getGoodsClasses(Model model,HttpServletRequest request,HttpServletResponse response) {
		GoodsClassCriteria criteria = new GoodsClassCriteria();
		criteria.andStateEquals("0");
		return goodsClassService.selectByCriteria(criteria);
	}
	//获取分类下的商品
	@RequestMapping(value = "/getClassGoodsInfos", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ServiceResult<List<GoodsInfoAO>> getClassGoodsInfos(Integer classId,Model model,HttpServletRequest request,HttpServletResponse response) {
		GoodsInfoCriteria criteria = new GoodsInfoCriteria();
		criteria.andClassIdEquals(classId).andStateEquals("0");
		return goodsInfoService.selectByCriteria(criteria);
	}
	//获取轮播图
	@RequestMapping(value = "/getBanners", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ServiceResult<List<BannerAO>> getBanners(Model model,HttpServletRequest request,HttpServletResponse response) {
		BannerCriteria criteria = new BannerCriteria();
		criteria.andLocationEquals("1").andStateEquals("0");
		return bannerService.selectByCriteria(criteria);
	}
	//获取热卖商品
	@RequestMapping(value = "/getHotGoodsInfos", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ServiceResult<List<GoodsInfoAO>> getHotGoodsInfos(Model model,HttpServletRequest request,HttpServletResponse response) {
		GoodsInfoCriteria criteria = new GoodsInfoCriteria();
		criteria.andHotSignEquals("1").andStateEquals("0");
		return goodsInfoService.selectByCriteria(criteria);
	}
	//获取新品商品
	@RequestMapping(value = "/getNewGoodsInfos", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ServiceResult<List<GoodsInfoAO>> getNewGoodsInfos(Model model,HttpServletRequest request,HttpServletResponse response) {
		GoodsInfoCriteria criteria = new GoodsInfoCriteria();
		criteria.andNewSignEquals("1").andStateEquals("0");
		return goodsInfoService.selectByCriteria(criteria);
	}
}
